package com.raos.example.mongo.morphia;

import com.mongodb.MongoClient;
import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.Key;
import org.mongodb.morphia.Morphia;

/**
 * mongodb 官方推荐的一个Java ORM 框架（Morphia）入门
 *
 * @author raos
 * @emil 991207823@qq.com
 * @date 2021/8/29 21:25
 */
public class MorphiaTest {

    public static void main(String[] args) {

        final Morphia morphia = new Morphia();
        final Datastore datastore = morphia.createDatastore(
                new MongoClient("127.0.0.1", 27017), "rao-test");

        Member member = new Member();
        member.setName("yufeng");
        member.setAge(20);
        member.setAddr("Chengdu Wuhou");

        Key<Member> key = datastore.save(member);
        System.out.println(member);
        System.out.println("获得主键：" + key.getId());

    }

}
